import * as compose from 'koa-compose'
import Application from './index'
import * as Router from './router'

let log = console.log;
let app = new Application();
app.use(async function (ctx, next) {
    log(1)
    let res = await next();
    log('1-res', res)
    return 1;
});
app.use(async function (ctx, next) {
    log(2)
    let res = await next();
    log('2-res', res)
    return 2;
});

let mids: any[] = [];
mids.push(async function (ctx, next) {
    log('m1')
    let res = await next();
    log('m1-res', res)
    return 'm1';
});
mids.push(async function (ctx, next) {
    log('m2')
    let res = await next();
    log('m2-res', res)
    return 'm2';
});
let fn = compose(mids);
app.use(fn);
app.context.path = '/get/123/sub'

let router = Router.get('/get/:id/:path', async function (ctx, next, args) {
    log(ctx);
    log(next);
    log(args);
    let res = await next();
    log('router-res', res)
});
app.use(router);

app.run().then((res) => {
    log()
    log('the first middleware result is :', res)
    log('app end!')
});